<template>
  <!-- 上架记录 -->
  <div>
    <el-card class="box-card" :body-style="{ padding: 10 }">
      <el-form :inline="true" :model="queryParam" class="demo-form-inline" size="medium">
        <el-form-item label="上架日期">
          <el-date-picker v-model="upDate" type="daterange" range-separator="至" start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="上架类型">
          <el-select v-model="queryParam.labelType" placeholder="请选择" clearable>
            <el-option v-for="item in [
              { value: 0, label: '档案上架' },
              { value: 1, label: '盒上架' },
            ]" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
          <el-button @click="rest">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <el-card class="box-card" :body-style="{ padding: 10 }">
      <el-table :data="tableData" border style="width: 100%" height="55vh">
        <el-table-column type="index" label="序号" align="center" width="50"></el-table-column>
        <el-table-column v-for="item of tableProps" :key="item.props" :prop="item.prop" :label="item.title"
          :width="item.width">
          <template #default="scope">
            <div v-if="item.prop === 'labelType'">
              <el-tag v-show="scope.row.labelType == 0" type="success">档案上架</el-tag>
              <el-tag v-show="scope.row.labelType == 1">盒上架</el-tag>
            </div>
            <div v-else-if="item.prop === 'dataSources'">
              <span v-show="scope.row.dataSources == 0">平台端</span>
              <span v-show="scope.row.dataSources == 1">终端设备</span>
              <span v-show="scope.row.dataSources == 2">数据接口</span>
            </div>
            <div v-else>{{ scope.row[item.prop] }}</div>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="100">
          <template slot-scope="{ row }">
            <el-button icon="el-icon-view" link size="mini" @click="handleShow(row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-card class="box-card" :body-style="{ padding: 10 }">
      <pagination ref="pagination" :totalCount="totalCount" @pagination="pagination"></pagination>
    </el-card>
    <up-bill-dialog ref="upBillDialog"></up-bill-dialog>
  </div>
</template>

<script>
import { upBillPageList } from '@/api/rfid/upBill'
import upBillDialog from './dialog/upBillDialog.vue'
import moment from 'moment'

export default {
  name: 'upBill',
  components: { upBillDialog },
  data() {
    return {
      totalCount: 0, //总数
      //查询条件
      searchModel: {
        pageNo: 1,
        pageSize: 10,
      },
      queryParam: {},
      upDate: [],
      tableData: [],
      tableProps: [
        { title: '上架单号', prop: 'billNumber', width: '', checked: true },
        { title: '上架时间', prop: 'upDate', width: '', checked: true },
        { title: '上架人', prop: 'upBy', width: '', checked: true },
        { title: '上架类型', prop: 'labelType', width: '', checked: true },
        { title: '数据来源', prop: 'dataSources', width: '', checked: true },
      ],
    }
  },

  mounted() {
    this.loadData()
  },

  methods: {
    onSubmit() {
      this.$refs.pagination.resetPagination()
    },
    rest() {
      this.upDate = []
      this.queryParam = {}
      this.$refs.pagination.resetPagination()
    },
    loadData() {
      if (this.upDate !== null && this.upDate.length > 0) {
        this.queryParam.beginTime = moment(this.upDate[0]).format('YYYY-MM-DD 00:00:00')
        this.queryParam.endTime = moment(this.upDate[1]).format('YYYY-MM-DD 23:59:59')
      } else {
        this.queryParam.beginTime = null
        this.queryParam.endTime = null
      }
      this.tableData = []
      var param = Object.assign(this.queryParam, this.searchModel)
      upBillPageList(param)
        .then((res) => {
          if (res.data.code === 200) {
            this.tableData = res.data.data.records
            this.totalCount = res.data.data.total
          } else {
            this.$message.error(res.data.message)
          }
        })
        .catch((err) => {
          this.$message.error(err)
        })
    },
    pagination(val) {
      this.searchModel.pageNo = val.page
      this.searchModel.pageSize = val.limit
      this.loadData()
    },
    handleShow(row) {
      this.$refs.upBillDialog.show(row)
    },
  },
}
</script>

<style lang="less" scoped>
.el-form-item {
  margin-bottom: 0 !important;
}
</style>
